
--[[
ngx.log辅助输出，可加入日志标记，便于跟踪日志
--]]

local setmetatable=setmetatable;
local _M={_VERSION="1.0"};
local _mt={__index=_M};

function _M.log(loglevel,msg,v1,v2,v3,v4,v5) 
   if v5~=nil then
      ngx.log(loglevel,string.format("[APPNAME:%s] %s%s%s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3,v4,v5))
   elseif v4~=nil then
      ngx.log(loglevel,string.format("[APPNAME:%s] %s%s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3,v4))
   elseif v3~=nil then
      ngx.log(loglevel,string.format("[APPNAME:%s] %s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3))
   elseif v2~=nil then
      ngx.log(loglevel,string.format("[APPNAME:%s] %s%s%s",ngx.var.APP_NAME,msg,v1,v2))
   elseif v1~=nil then
      ngx.log(loglevel,string.format("[APPNAME:%s] %s%s",ngx.var.APP_NAME,msg,v1))
   else
      ngx.log(loglevel,string.format("[APPNAME:%s] %s",ngx.var.APP_NAME,msg))
   end 
end

function _M.formatMsg(msg,v1,v2,v3,v4,v5) 
   if v5~=nil then
      return string.format("[APPNAME:%s] %s%s%s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3,v4,v5)
   elseif v4~=nil then
      return string.format("[APPNAME:%s] %s%s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3,v4)
   elseif v3~=nil then
      return string.format("[APPNAME:%s] %s%s%s%s",ngx.var.APP_NAME,msg,v1,v2,v3)
   elseif v2~=nil then
      return string.format("[APPNAME:%s] %s%s%s",ngx.var.APP_NAME,msg,v1,v2)
   elseif v1~=nil then
      return string.format("[APPNAME:%s] %s%s",ngx.var.APP_NAME,msg,v1)
   else
      return string.format("[APPNAME:%s] %s",ngx.var.APP_NAME,msg)
   end 
end
setmetatable(_M,_mt);


return _M;


